package com.expensetracker.dto;

import static javax.persistence.GenerationType.SEQUENCE;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="expense")
public class Expense implements Serializable {
	
	private static final long serialVersionUID = -567500940384654825L;
	private Long id;
	private ExpenseTransaction transaction;
	private Double amount;
	private ExpenseType expenseType;
	
	@SequenceGenerator(name = "generator", sequenceName = "expense_id_seq")
	@Id
	@GeneratedValue(strategy = SEQUENCE, generator = "generator")
	@Column(name = "ID", unique = true, nullable = false)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	@ManyToOne( cascade=CascadeType.ALL, fetch=FetchType.LAZY )
	@JoinColumn(name="TRANSACTION", nullable = false)	
	public ExpenseTransaction getTransaction() {
		return transaction;
	}
	public void setTransaction(ExpenseTransaction transaction) {
		this.transaction = transaction;
	}
	
	@Column(name = "AMOUNT", nullable = false, precision = 8, scale = 2)
	public Double getAmount() {
		return amount;
	}
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	
	@ManyToOne()
	@JoinColumn(name="TYPE")
	public ExpenseType getExpenseType() {
		return expenseType;
	}
	public void setExpenseType(ExpenseType expenseType) {
		this.expenseType = expenseType;
	}
	
	
}
